#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m;

void solve() {
    cin >> n >> m;
    if(n == m) {
        cout << "YES" << endl;
        return;
    }
    if(m > n) {
        cout << "NO" << endl;
        return;
    }
    int g = __gcd(n, m);
    int a = n / g, b = m / g;
    while(a > 1) {
        if(a % 3) {
            cout << "NO" << endl;
            return;
        }
        a /= 3;
    }
    while(b > 1) {
        if(b % 2) {
            cout << "NO" << endl;
            return;
        }
        b /= 2;
    }

    cout << "YES" << endl;
}

signed main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}